import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service: 服务器定义
 * @date: 2019-7-1
 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
/**
 * 查询列表
 * @async
 * @function fetchServerList
 * @param {Object} params - 查询参数
 */

export function fetchServerList(_x) {
  return _fetchServerList.apply(this, arguments);
}
/**
 * 获取服务器明细
 * @async
 * @function getServerDetail
 * @param {Object} params - 查询参数
 */

function _fetchServerList() {
  _fetchServerList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "servers"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchServerList.apply(this, arguments);
}

export function getServerDetail(_x2) {
  return _getServerDetail.apply(this, arguments);
}
/**
 * 新建服务器
 * @async
 * @function createServer
 * @param {Object} params - 查询参数
 */

function _getServerDetail() {
  _getServerDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var serverId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            serverId = params.serverId;
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "servers/").concat(serverId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _getServerDetail.apply(this, arguments);
}

export function createServer(_x3) {
  return _createServer.apply(this, arguments);
}
/**
 * 编辑服务器
 * @async
 * @function editServer
 * @param {Object} params - 查询参数
 */

function _createServer() {
  _createServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "servers"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createServer.apply(this, arguments);
}

export function editServer(_x4) {
  return _editServer.apply(this, arguments);
}
/**
 * 删除服务器
 * @async
 * @function deleteServer
 * @param {Object} params - 查询参数
 */

function _editServer() {
  _editServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "servers"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _editServer.apply(this, arguments);
}

export function deleteServer(_x5) {
  return _deleteServer.apply(this, arguments);
}
/**
 * 重置密码
 * @async
 * @function resetPssword
 * @param {Object} params - 查询参数
 */

function _deleteServer() {
  _deleteServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "servers"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteServer.apply(this, arguments);
}

export function resetPssword(_x6) {
  return _resetPssword.apply(this, arguments);
}
/**
 * 获取服务器集群
 * @async
 * @function getServerCluster
 * @param {Object} params - 查询参数
 */

function _resetPssword() {
  _resetPssword = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "servers"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _resetPssword.apply(this, arguments);
}

export function getServerCluster(_x7) {
  return _getServerCluster.apply(this, arguments);
}

function _getServerCluster() {
  _getServerCluster = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    var serverId;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            serverId = params.serverId;
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "servers/clusters/server-id/").concat(serverId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _getServerCluster.apply(this, arguments);
}